-----------------------------------	
-- Area: Valkurm Dunes	
-- NPC:  Field Manual	
-----------------------------------	
	
require("/scripts/globals/settings");	
require("/scripts/globals/fieldsofvalor");	
require("scripts/globals/keyitems");
	
-----------------------------------	
-- onTrigger Action	
-----------------------------------	
	
function onTrigger(player,npc)
	local npc = GetNPCByID(17199750); -- mog-tablet
	local tabletmove = player:getVar("mishimove"); -- move step
	
	if(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 1) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-183,-3,-23);
    player:setVar("mishimove",2);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 2) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-172,-3,13);
	player:setVar("mishimove",3);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 3) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-146,-3,16);
	player:setVar("mishimove",4);
    elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 4) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-137,-1,51);
	player:setVar("mishimove",5);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 5) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-114,-3,59);
	player:setVar("mishimove",6);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 6) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-103,-3,16);
	player:setVar("mishimove",7);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 7) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-132,0,-4);
	player:setVar("mishimove",8);
    elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 8) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-158,-2,18);
	player:setVar("mishimove",9);
	 elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 9) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-158,-2,60);
	player:setVar("mishimove",10);
	 elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 10) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-142,-3,97);
	player:setVar("mishimove",11);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 11) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-111,-7,109);
	player:setVar("mishimove",12);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 12) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-78,-6,104);
	player:setVar("mishimove",13);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 13) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-38,-7,92);
	player:setVar("mishimove",14);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 14) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(-12,-8,105);
	player:setVar("mishimove",15);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 15) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(21,-8,104);
	player:setVar("mishimove",16);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 16) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(56,-8,98);
	player:setVar("mishimove",17);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 17) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(81,-7,92);
	player:setVar("mishimove",18);	
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 18) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(113,-7,85);
	player:setVar("mishimove",19);	
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 19) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(124,-6,96);
	player:setVar("mishimove",20);	
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 20) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(131,-7,88);
	player:setVar("mishimove",21);	
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 21) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(124,-7,110);
	player:setVar("mishimove",22);	
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 22) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(146,-7,112);
	player:setVar("mishimove",23);		
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 23) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(132,-7,96);
	player:setVar("mishimove",24);	
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 24) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(135,-7,95);
	player:setVar("mishimove",25);	
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 25) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(134,-7,97);
	player:setVar("mishimove",26);	
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 26) then-- has moogle key  move NPC
	player:messageSpecial(6391,4306);
	npc:setPos(132,-7,95);
	player:setVar("mishimove",27);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 27) then-- has moogle key  move NPC	

stock = {0x139f,8160,	-- Scroll of Goblin Gavotte 
	 5765,75000,	-- red curry bun
	 5718,75000,	-- cream puff
	 5174,75000,    -- tacos
	 5163,75000,    -- sole sushi
	 4199,50000,     -- str pot
	 4213,200000,    -- ic wing
	 4207,50000,    -- intel pot
	 4201,50000,     -- dex pot
	 4205,50000,     -- agi pot
	 268,500000,     -- mog pop
	 4558,20000,     -- yag drink
	 4174,250000}       -- vile elixir
	 

showShop(player, STATIC, stock);
	player:setVar("mishimove",28);
	elseif(player:hasKeyItem(MOOGLE_KEY) == true and  player:getVar("mishimove")== 28) then-- has moogle key  move NPC
	--	player:messageSpecial(8107); -- that item cannot be traded
		player:messageSpecial(11278,17); -- its u mog tablet finder
		player:messageSpecial(6398); -- not enough gill
		player:setVar("mishimove",1);
		npc:setPos(-208,0,-50);	
	elseif(player:hasKeyItem(MOOGLE_KEY) == false) then-- has no moogle key, dont move
	player:messageSpecial(6391,4306);
	end
end;	
	
-----------------------------------	
-- onTrade Action	
-----------------------------------	
	
function onTrade(player,npc,trade)
	local npc = GetNPCByID(17199750); -- mog-tablet
		if (trade:hasItemQty(4306,1) and (player:hasKeyItem(MOOGLE_KEY) == false)) then -- donko trade I want key item
			player:addKeyItem(MOOGLE_KEY);
		    player:setVar("mishimove",1);
			player:messageSpecial(6394,1184);
			player:messageSpecial(6403,4306);		
		elseif (trade:hasItemQty(4306,1) and (player:hasKeyItem(MOOGLE_KEY) == true)) then -- donko trade I want key item
			player:delKeyItem(MOOGLE_KEY);
			player:messageSpecial(6395,1184); 
			player:messageSpecial(6403,4306);
		elseif (trade:hasItemQty(268,1) and player:getVar("mishimove")== 28) then 
		SpawnMob(17199438,300):updateEnmity(player); -- spawn hobgoblin beastmaster
		player:messageSpecial(6657);		
		player:tradeComplete(trade);
		player:setVar("mishimove",1);
		npc:setPos(-208,0,-50);	
		end
end;	
	
-----------------------------------	
-- onEventSelection	
-----------------------------------	
	
function onEventUpdate(player,csid,menuchoice)	
	updateFov(player,csid,menuchoice,7,8,9,10,57);
end;	
	
-----------------------------------	
-- onEventFinish Action	
-----------------------------------	
	
function onEventFinish(player,csid,option)	
	finishFov(player,csid,option,7,8,9,10,57,FOV_MSG_VALKURM);
end;	
